package com.lebang.controller.sys.cences;

import com.alibaba.fastjson.JSONObject;
import com.lebang.common.Login;
import com.lebang.domain.CencesNewusersCityscale;
import com.lebang.example.CencesNewusersCityscaleExample;
import com.lebang.service.cences.CencesNewusersCityscaleService;
import com.lebangweb.common.TextUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;


/**
 *
 * @author ljx
 * @date 2020-11-24
 */
@Controller
@RequestMapping("/sys/cencesnewuserscityscale")
public class CencesNewusersCityscaleController {
    @Autowired
    private CencesNewusersCityscaleService baseService;

    @Login
    @GetMapping("/get/list")
    public String list(Model model, String appStore,String time) {
        model.addAttribute("appStore", appStore);
        model.addAttribute("time", time);
        return "/cencesnewuserscityscale/list";
    }


    @Login
    @ApiOperation(value = "分页")
    @PostMapping("/list")
    @ResponseBody
    public JSONObject list(HttpServletRequest request, @RequestParam Integer page, @RequestParam Integer limit,String appStore,Integer time) {
        CencesNewusersCityscaleExample example = new CencesNewusersCityscaleExample();
        example.setOffset((page - 1) * limit.longValue());
        example.setLimit(limit);
        example.setOrderByClause("time desc,id desc");
        CencesNewusersCityscaleExample.Criteria criteria = example.createCriteria();
        criteria.andAppStoreEqualTo(appStore);
        if (!TextUtil.isEmpty(time)){
            criteria.andTimeEqualTo(time);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 0);
        jsonObject.put("data", baseService.selectByExample(example));
        jsonObject.put("count", baseService.countByExample(example));
        return jsonObject;
    }
}
